package com.hl.icd.interceptor;

import com.hl.icd.utils.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class AuthInterceptor implements HandlerInterceptor {

    @Autowired
    private JwtUtil jwtUtil;

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        if(!request.getMethod().equals("OPTIONS")){
            String token = request.getHeader("token");
            if(token == null){
                System.out.println("token为空");
                return false;
            }
            try {
                jwtUtil.parseJWT(token);
            } catch (Exception e) {
                e.printStackTrace();
                return false;
            }
        }
        return true;
    }


}
